<script type="text/javascript">

function mod_all_checkbox(class_name) {
    var i = 1;
    $('.'+class_name).each(function() {
        if (i==1) {
            if (this.checked == true) {
                i = 2;
            } else {
                i = 3;
            }
        }

        if (i == 3) {
            this.checked = false;
        } else {
            this.checked = true;
        }
    });
}

function change_check_all_status(class_name, check_all_id) {
    status = true;
    $('.'+class_name).each(function() {
        if (this.id == check_all_id) {
            check_all = this;
        } else {
            if (this.checked == false) {
                status = false;
            }
        }
    });
    if (status) {
        check_all.checked = true;
    } else {
        check_all.checked = false;
    }
}

function check_form() {
    var group_title = document.getElementById('group_title');
    if (group_title.value == '') {
        alert('<?php __e('Group title is empty'); ?>');
        group_title.focus();
        return false;
    }
}
</script>
<div id="sub-menu-box"> <?php echo $html->admin_link(' &laquo; ' . __('Return Groups'), '/groups'); ?></div>
<div id="content">
  <h2><?php echo $action_title; ?></h2>
<p></p>

  <form action="<?php echo $html->admin_url('/groups/group_new'); ?>" method="post" id="settings" onsubmit="return check_form();">
<?php echo $html->input('Groups/id', array('type'=>'hidden')); ?>
    <table>
      <tr>
        <th><?php __e('Group title'); ?></th>
        <td>
            <?php echo $html->input('Groups/title', array('size'=>40,'type'=>'text', 'id'=>'group_title')); ?>
<?php
    if (!empty($is_anonymous)) {
?>
 <span class="u"><?php __e('This is a anonymous user group'); ?></span>
<?php
}
?>
        </td>
      </tr>
      <tr>
        <th><?php __e('Group description'); ?></th>
        <td>
          <?php echo $html->textarea('Groups/description', array('rows'=>6, 'cols'=>40)); ?>
         </td>
      </tr>
<!--
<tr id="reading_role_default">
        <th>Reading role</th>
        <td>

<span class="u">(默认为游客权限)</span> &nbsp;&nbsp;<a href="" onclick="showItem('reading_role'); hideItem('reading_role_default'); return false;">设置阅读权限</a>
        </td>
</tr>
-->
<!--
      <tr id="reading_role" >
        <th><?php __e('Page Manage role'); ?></th>
        <td>
<?php
if (!empty($diagrams)) {
?>
        <table>
          <tr class="finalrow">
            <th>All</th>
            <td>
<?php echo $html->checkbox('Reading/check_all', array('id'=>'cap_read_check_all', 'onclick'=>'mod_all_checkbox(\'cap_reading\');', 'value'=>'all','class'=>'cap_reading')); ?>
<label for="cap_read_check_all"> 阅读</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $html->checkbox('Comment/check_all', array('id'=>'cap_comment_check_all', 'onclick'=>'mod_all_checkbox(\'cap_comment\');', 'value'=>'all','class'=>'cap_comment')); ?>
<label for="cap_comment_check_all"> 评论</label>
  </td>
          </tr>
<?php
foreach($diagrams as $diagram) {
    if ($diagram->type == 'page') {
?>
          <tr class="finalrow">
            <th><?php echo $diagram->title; ?></th>
            <td>
<?php echo $html->checkbox($Reading . '/cap_read_' . $diagram->id, array('id'=>'cap_read_' . $diagram->id, 'value'=>$diagram->id, 'class'=>'cap_reading', 'onclick'=>'change_check_all_status(\'cap_reading\', \'cap_read_check_all\')')); ?>

<label for="cap_read_<?php echo $diagram->id; ?>"> 阅读</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $html->checkbox($Comment . '/cap_comment_' . $diagram->id, array('id'=>'cap_comment_' . $diagram->id, 'value'=>$diagram->id, 'class'=>'cap_comment', 'onclick'=>'change_check_all_status(\'cap_comment\', \'cap_comment_check_all\')')); ?>

<label for="cap_comment_<?php echo $diagram->id; ?>"> 评论</label>
            </td></tr>
<?php
    }
}
?>
        </table>
<?php
}
?>
        </td>
      </tr>
-->
<?php
if (empty($is_anonymous)) {
?>
<!--
<tr id="manage_role_default">
        <th><?php __e('Manage role'); ?></th>
        <td>

<span class="u">(默认为游客权限)</span> &nbsp;&nbsp;<a href="" onclick="showItem('manage_role'); hideItem('manage_role_default'); return false;">设置阅读权限</a>


        </td>
</tr>
-->
      <tr id="manage_role" >
        <th><?php __e('Posts Manage role'); ?></th>
        <td>
<?php
if (!empty($diagrams)) {
?>
        <table>
          <tr class="finalrow">
            <th>All</th>
            <td>
<?php echo $html->checkbox('Manage/check_all_own', array('id'=>'cap_manage_check_all_own', 'onclick'=>'mod_all_checkbox(\'cap_manage_own\');', 'value'=>'all','class'=>'cap_manage_own')); ?>
<label for="cap_manage_check_all_own"> 仅发表和管理自己的文章</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $html->checkbox('Manage/check_all_all', array('id'=>'cap_manage_check_all_all', 'onclick'=>'mod_all_checkbox(\'cap_manage_all\');', 'value'=>'all','class'=>'cap_manage_all')); ?>
<label for="cap_manage_check_all_all"> 还可以管理该分类下其他人的文章</label>
  </td>
          </tr>
<?php
foreach($diagrams as $diagram) {
    if ($diagram->type == 'list') {
?>
          <tr class="finalrow">
            <th><?php echo $diagram->title; ?></th>
            <td>
<?php echo $html->checkbox('Manage_category/cap_manage_own_' . $diagram->id, array('id'=>'cap_manage_own_' . $diagram->id, 'value'=>$diagram->id, 'class'=>'cap_manage_own', 'onclick'=>'change_check_all_status(\'cap_manage_own\', \'cap_manage_check_all_own\')')); ?>
<label for="cap_manage_own_<?php echo $diagram->id; ?>"> 仅发表和管理自己的文章</label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $html->checkbox('Manage_category/cap_manage_all_' . $diagram->id, array('id'=>'cap_manage_all_' . $diagram->id, 'value'=>$diagram->id, 'class'=>'cap_manage_all', 'onclick'=>'change_check_all_status(\'cap_manage_all\', \'cap_manage_check_all_all\')')); ?>
<label for="cap_manage_all_<?php echo $diagram->id; ?>"> 还可以管理该分类下其他人的文章</label>

</td></tr>
<?php
    }
}
?>
        </table>
<?php
}
?>
        </td>
      </tr>
    <tr>
        <th>后台管理权限</th>
        <td>
<?php
if (isset($al_sub_menu) && is_array($al_sub_menu) && !empty($al_sub_menu)) {
?>
            <table>
          <tbody>
<?php
foreach($al_sub_menu as $key => $sub_menu) {
    foreach( $sub_menu as $menu) {
        if (isset($menu['action'])) {
        array_unshift($menu['action'], 'none');
        if (empty($this->data['Admin'][$menu[0]])) {
            $this->data['Admin'][$menu[0]] = 'none';
        }
?>
          <tr class="finalrow">
            <th><?php __e($menu[0]); ?></th>
            <td>
<?php
            foreach($menu['action'] as $action) {
?>
<?php echo $html->radio('Admin/' . $menu[1], array('value'=>$action, 'id'=>$menu[1] . '_' . $action)); ?>
<label for="<?php echo $menu[1] . '_' . $action; ?>"> <?php __e($action); ?></label>
<?php
            }
?>
            </td></tr>
<?php
        }
    }
}
?>
        </tbody></table>
<?php
}
?>
        </td>
      </tr>
<?php
}
?>
      <tr class="finalrow">
        <th></th>
        <td><input value="<?php echo $submit_value; ?>" type="submit" class="mainbutton" onclick="clear_isset_monitoring();">
<input value="<?php __e('Cancel'); ?>" class="cancel" onclick="window.location = '<?php echo $html->admin_url('/groups'); ?>';" type="button">
        </td>
      </tr>
    </table>
  </form>
</div>
